<?php
namespace Admin\Model;

use Think\Model;

class NodeModel extends Model{
    protected $patchValidate = true;
    protected $_validate = array(
        array('node_name','require','权限名称不能为空！',self::MUST_VALIDATE),
        array('node_name','checkNodeUnique_add','该权限已经存在！',self::MUST_VALIDATE,'callback','add'),
        array('node_name','checkNodeUnique','该权限已经存在！',self::MUST_VALIDATE,'callback','edit'),
        array('controller','require','控制器不能为空！',self::MUST_VALIDATE),
    );
    protected function checkNodeUnique($param)
    {
       $where="node_name='%s' AND id!='%d'";
        $num=M("Node")->where($where,$param,$this->id)->count();
        if($num){
          return false;
        }
    }
    protected function checkNodeUnique_add($param)
    {
        $where="node_name='%s'";
        $num=M("Node")->where($where,$param)->count();
        if($num){
            return false;
        }
    }
}

?>